package demoMod.nanaki.vfx;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.MathUtils;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.powers.AbstractPower;
import com.megacrit.cardcrawl.vfx.AbstractGameEffect;

public class NoteFlashEffect extends AbstractGameEffect {
    private final float x;
    private final float y;
    private final TextureAtlas.AtlasRegion img;
    private boolean playedSound = false;

    public NoteFlashEffect(float x, float y) {
        this.img = AbstractPower.atlas.findRegion("128/hymn");
        this.x = x - (float)this.img.packedWidth / 2.0F;
        this.y = y - (float)this.img.packedHeight / 2.0F;
        this.startingDuration = 0.5F;
        this.duration = this.startingDuration;
        this.color = Color.WHITE.cpy();
    }

    public void update() {
        if (!this.playedSound) {
            CardCrawlGame.sound.playA("BLOCK_ATTACK", -0.5F);
            this.playedSound = true;
        }

        super.update();
    }

    @Override
    public void render(SpriteBatch sb) {
        sb.setBlendFunction(770, 1);
        sb.setColor(this.color);
        sb.draw(this.img, this.x, this.y, (float)this.img.packedWidth / 2.0F, (float)this.img.packedHeight / 2.0F, (float)this.img.packedWidth, (float)this.img.packedHeight, this.scale * MathUtils.random(2.9F, 3.1F), this.scale * MathUtils.random(2.9F, 3.1F), this.rotation);
        sb.draw(this.img, this.x, this.y, (float)this.img.packedWidth / 2.0F, (float)this.img.packedHeight / 2.0F, (float)this.img.packedWidth, (float)this.img.packedHeight, this.scale * MathUtils.random(2.9F, 3.1F), this.scale * MathUtils.random(2.9F, 3.1F), this.rotation);
        sb.setBlendFunction(770, 771);
    }

    @Override
    public void dispose() {

    }
}
